package si.yun.web;

import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import si.yun.entity.*;
import si.yun.service.PersonnelService;
import si.yun.utils.JsonData;
import si.yun.utils.Md5Utils;
import si.yun.utils.TemplateExcelUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * @program: SiYunClass
 * @description: 人事功能web层
 * @author: 崔晓晨
 * @create: 2021-07-28 20:47
 **/
@RestController
@RequestMapping("/personnel")
@PropertySource({"config.properties"})
public class PersonnelWeb {
    @Autowired
    private PersonnelService personnelService;
    /*后台用户获取路径*/
    @Value("${backuserpath}")
    private String backuserpath;
    //后台上传路径
    @Value("${importbackpath}")
    private String importbackpath;
    //前台上传路径
    @Value("${importbeforepath}")
    private String importbeforepath;
    //前台上传路径
    @Value("${beforeuserpath}")
    private String beforeuserpath;
    /**
     * @return si.yun.entity.PerCount
     * @Description 获取用户数据展示
     * @Date 2021/7/29 14:37
     **/
    @GetMapping("/selUserNum")
    public PerCount selUserNum() {
        PerCount perCount = personnelService.selUserNum();
        return perCount;
    }
    /**
     * @return si.yun.entity.SyApplyRecord
     * @Description 获取期间内申请人员统计信息
     * @Date 2021/7/28 21:03
     **/
    @RequestMapping("/selPerTab")
    public List<PerCount> selPerTab(int durDate) {
        PerCount selPerTab = personnelService.selPerTab(durDate);
        List<PerCount> list = new ArrayList<>();
        list.add(selPerTab);
        return list;
    }
    /**
     * @return java.util.Map<java.lang.String , java.lang.Object>
     * @Description 申请人统计
     * @Date 2021/7/29 13:28
     **/
    @PostMapping("/selEcharts")
    public Map<String, Object> selEcharts(int durDate) {
        PerCount selPerTab = personnelService.selPerTab(durDate);
        Map<String, Object> map = new HashMap<>();
        map.put("applyNum", selPerTab.getApplyNum());
        map.put("applyPass", selPerTab.getApplyPass());
        map.put("applyRejection", selPerTab.getApplyRejection());
        return map;
    }
    /**
     * @return java.util.List<java.lang.Integer>
     * @Description 获取用户统计
     * @Date 2021/7/29 13:32
     **/
    @GetMapping("/selUserEcharts")
    public List<Integer> selUserEcharts() {
        List<Integer> integers = personnelService.selUserEcharts();
        return integers;
    }
    /**
     * @return si.yun.entity.JsonData
     * @Description 获取用户列表
     * @Date 2021/7/29 19:22
     **/
    @PostMapping("/selUserTable")
    public List<SyBeforeUser> selUserTable(SyBeforeUser beforeUser) {
        List<SyBeforeUser> beforeUsers = personnelService.selUserTable(beforeUser);
        return beforeUsers;
    }
    /**
     * @return boolean
     * @Description 添加停用的用户
     * @Date 2021/8/1 18:36
     **/
    @PostMapping("/addClosure")
    public boolean addClosure(SyClosure closure) {
        int add = personnelService.addClosure(closure);
        if (add != 0) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * @return si.yun.entity.SyBeforeUser
     * @Description 查询单个用户的详细信息
     * @Date 2021/8/1 18:58
     **/
    @PostMapping("/selUserInfo")
    public SyBeforeUser selUserInfo(int userId) {
        SyBeforeUser beforeUser = personnelService.selUserInfo(userId);
        return beforeUser;
    }
    /**
     * @Description  查询单个后台用户的详细信息
     * @return si.yun.entity.SyUser
     * @Date 2021/8/21 10:42
     **/
    @PostMapping("/selBackUserInfo")
    public SyUser selBackUserInfo(int userId) {
        SyUser beforeUser = personnelService.selBackUserInfo(userId);
        return beforeUser;
    }
    /**
     * @return boolean
     * @Description 编译用户信息 ( 不能编译用户的学习时长  和 交易金额 以及 账号创建时间)
     * @Date 2021/8/1 20:48
     **/
    @PostMapping("/updSelUser")
    public boolean updSelUser(SyBeforeUser beforeUser) {
        int upd = personnelService.updSelUser(beforeUser);
        if (upd != 0) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * @return si.yun.entity.SyClosure
     * @Description 查询封号用户列表
     * @Date 2021/8/2 9:42
     **/
    @PostMapping("/selClosureUserTable")
    public List<SyClosure> selClosureUserTable(SyClosure closure) {
        List<SyClosure> closures = personnelService.selClosureUserTable(closure);
        return closures;
    }
    /**
     * @return boolean
     * @Description 解封用户 改变封号列表信息
     * @Date 2021/8/2 15:11
     **/
    @PostMapping("/updClosure")
    public boolean updClosure(SyClosure closure) {
        int upd = personnelService.updClosure(closure);
        if (upd != 0) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * @return boolean
     * @Description 删除停用后的封停日志
     * @Date 2021/7/30 15:38
     **/
    @PostMapping("/delBeforeStatus")
    public boolean delBeforeStatus(int id) {
        int del = personnelService.delBeforeStatus(id);
        if (del != 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @return si.yun.utils.JsonData
     * @Description 查询进思用户列表的详细数据
     * @Date 2021/8/3 10:04
     **/
    @PostMapping("/selThinkUserTable")
    public JsonData selThinkUserTable(PerUserListThink userThink) {
        List<PerUserListThink> list = personnelService.selThinkUserTable(userThink);
        return list != null ? JsonData.buildSuccess(list) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @return si.yun.utils.JsonData
     * @Description 查看进思用户的详细信息
     * @Date 2021/8/3 20:48
     **/
    @PostMapping("/selUserThinkIndex")
    public JsonData selUserThinkIndex(int developmentId) {
        PerUserListThink development = personnelService.selUserThinkIndex(developmentId);
        return development != null ? JsonData.buildSuccess(development) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  上传图片文件 更换头像
     * @return si.yun.utils.JsonData
     * @Date 2021/8/4 19:48
     **/
    @PostMapping("/updImg")
    public JsonData updImg(@RequestParam("file") MultipartFile files, HttpServletRequest request, int userId,int developmentId, HttpSession session) throws IllegalStateException, IOException {
        String realPath = importbeforepath;
        String newName = uploadFile(files, request, session,realPath);
        int upd = personnelService.updImg(developmentId,newName,userId);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    public String  uploadFile(@RequestParam("file") MultipartFile files, HttpServletRequest request,HttpSession session,String realPath) throws IllegalStateException, IOException {
        //创建file
        File tempFile = new File(realPath);
        if (!tempFile.isDirectory()) {
            tempFile.mkdirs();
        }
        long currTime = System.currentTimeMillis();
        //1.获取后缀名
        String uniqueName = files.getOriginalFilename();//得到文件名
        String suffix = uniqueName.substring(uniqueName.lastIndexOf(".") + 1);//截取扩展名
        //2.得到文件路径
        String newName = uniqueName.substring(0, uniqueName.lastIndexOf(".")) + "_" + currTime + "." + suffix;
        String filePath = realPath + File.separator + newName;
        files.transferTo(new File(filePath));//转存文件对象到list集合中
        return newName;
    }
    /**
     * @Description  编译进思用户的基本信息
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/5 9:30
     **/
    @PostMapping("/updThinkInfo")
    public JsonData updThinkInfo(PerUserListThink perUserListThink){
        int upd = personnelService.updThinkInfo(perUserListThink);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询优惠券列表
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/5 10:55
     **/
    @GetMapping("/selAwayListTab")
    public JsonData selAwayListTab(){
        List<OperCoupons> list = personnelService.selAwayListTab();
        return list != null ? JsonData.buildSuccess(list) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  添加 赠送优惠券的优惠券记录
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/5 14:12
     **/
    @PostMapping("/addUserCoupons")
    public JsonData addUserCoupons(@RequestParam List<Integer> userId,@RequestParam List<Integer> couponId){
        int add = personnelService.addUserCoupons(userId,couponId);
        return add != 0 ? JsonData.buildSuccess(add) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  添加进思用户列表
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/6 11:07
     **/
    @PostMapping("/addThinkUserInfo")
    public JsonData addThinkUserInfo(SyUserDevelopment development){
        int add = personnelService.addThinkUserInfo(development);
        return add != 0 ? JsonData.buildSuccess(add) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  添加后端操作日志
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/6 14:09
     **/
    @PostMapping("/addOperationLog")
    public JsonData addOperationLog(SyOperationLog log){
        int add = personnelService.addOperationLog(log);
        return add != 0 ? JsonData.buildSuccess(add) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  添加封号操作日志
     * @return si.yun.utils.JsonData
     * @Date 2021/8/6 16:22
     **/
    @PostMapping("/addClosureLog")
    public JsonData addClosureLog(SyClosureLog syClosureLog){
        int add = personnelService.addClosureLog(syClosureLog);
        return add != 0 ? JsonData.buildSuccess(add) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询封号日志表
     * @return java.util.List<si.yun.entity.PerClosureLog>
     * @Date 2021/8/6 17:23
     **/
    @PostMapping("/selClosureLog")
    public JsonData selClosureLog(PerClosureLog log) {
       List<PerClosureLog> perClosureLogs = personnelService.selClosureLog(log);
       return perClosureLogs != null ? JsonData.buildSuccess(perClosureLogs) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  删除封号日志
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/9 9:12
     **/
    @PostMapping("/delClosureLog")
    public JsonData delClosureLog(int id){
        int del = personnelService.delClosureLog(id);
        return del != 0 ? JsonData.buildSuccess(del) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查看操作日志
     * @return si.yun.utils.JsonData
     * @Date 2021/8/10 9:16
     **/
    @PostMapping("/selOperationLog")
    public JsonData selOperationLog(SyOperationLog operationLog){
        List<SyOperationLog> syOperationLogs = personnelService.selOperationLog(operationLog);
        return syOperationLogs != null ? JsonData.buildSuccess(syOperationLogs) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  删除操作日志、
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/10 9:17
     **/
    @PostMapping("/delOperationLog")
    public JsonData delOperationLog(int id){
        int del = personnelService.delOperationLog(id);
        return del != 0 ? JsonData.buildSuccess(del) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  获取非进思用户列表
     * @return si.yun.utils.JsonData
     * @Date 2021/8/10 10:03
     **/
    @PostMapping("/selNotThinkUser")
    public JsonData selNotThinkUser(SyBeforeUser beforeUser){
        List<SyBeforeUser> beforeUsers = personnelService.selNotThinkUser(beforeUser);
        return beforeUsers != null ? JsonData.buildSuccess(beforeUsers) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查看前台用户反馈列表
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/10 17:01
     **/
    @PostMapping("/selFeedbackList")
    public JsonData selFeedbackList(PerFeedback feedback){
        List<PerFeedback> feedbacks = personnelService.selFeedbackList(feedback);
        return feedbacks != null ? JsonData.buildSuccess(feedbacks) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询待审核 已受理的数量（反馈列表）
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/12 19:41
     **/
    @GetMapping("/selAduFeedNum")
    public JsonData selAduFeedNum(){
        PerFeedback feedback = personnelService.selAduFeedNum();
        return feedback != null ? JsonData.buildSuccess(feedback) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  更新已受理状态
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/13 9:00
     **/
    @PostMapping("/updFeedback")
    public JsonData updFeedback(Integer feedbackStatus,Integer feedbackId){
        int upd = personnelService.updFeedback(feedbackStatus,feedbackId);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查看受理详情
     * @return si.yun.utils.JsonData
     * @Date 2021/8/13 11:04
     **/
    @PostMapping("/selReceiveInfo")
    public JsonData selReceiveInfo(String tablename,String remark){
        PerOperationLog feedback = personnelService.selReceiveInfo(tablename,remark);
        return feedback != null ? JsonData.buildSuccess(feedback) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  删除反馈信息
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/13 11:30
     **/
    @PostMapping("/delFeedback")
    public JsonData delFeedback(Integer feedbackId){
        int del = personnelService.delFeedback(feedbackId);
        return del != 0 ? JsonData.buildSuccess(del) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询无消费记录用户列表
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/13 17:03
     **/
    @PostMapping("/selNotSpendUser")
    public JsonData selNotSpendUser(SyBeforeUser beforeUser){
        List<SyBeforeUser> beforeUsers = personnelService.selNotSpendUser(beforeUser);
        return beforeUsers != null ? JsonData.buildSuccess(beforeUsers) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询部门数据管理列表
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/14 9:48
     **/
    @PostMapping("/selDeptList")
    public JsonData selDeptList(PerDept dept){
        List<PerDept> perDepts = personnelService.selDeptList(dept);
        return perDepts != null ? JsonData.buildSuccess(perDepts) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  更新部门启用 停用状态
     * @return si.yun.utils.JsonData
     * @Date 2021/8/14 14:59
     **/
    @PostMapping("/updDeptStatus")
    public JsonData updDeptStatus(Integer deptId,Integer deptStatus){
        int upd = personnelService.updDeptStatus(deptId,deptStatus);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  修改部门信息
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/15 9:27
     **/
    @PostMapping("/updDeptInfo")
    public JsonData updDeptInfo(SyDept dept){
        int upd = personnelService.updDeptInfo(dept);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  添加部门
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/15 10:26
     **/
    @PostMapping("/addDeptInfo")
    public JsonData addDeptInfo(PerDept dept){
        int add = personnelService.addDeptInfo(dept);
        return add != 0 ? JsonData.buildSuccess(add) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  删除部门信息
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/15 14:03
     **/
    @PostMapping("/delDeptInfo")
    public JsonData delDeptInfo(Integer deptId){
        int del = personnelService.delDeptInfo(deptId);
        return del != 0 ? JsonData.buildSuccess(del) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  获取部门信息（树形）
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/16 19:03
     **/
    @GetMapping("/selDeptName")
    public JsonData selDeptName(){
        List<PerDeptZtreeNode> deptZtreeNodes = personnelService.selDeptName();
        Map<String, Object> mapTitle = new HashMap<>();
        mapTitle.put("menuName", "所有部门");
        mapTitle.put("id", "99999");
        mapTitle.put("children",deptZtreeNodes);
        return mapTitle != null ? JsonData.buildSuccess(mapTitle) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  获取后台管理员信息
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/16 20:24
     **/
    @PostMapping("/selBackUserList")
    public JsonData selBackUserList(PerBackUser user){
        List<PerBackUser> syUsers = personnelService.selBackUserList(user);
        for(PerBackUser us:syUsers){
            us.setAvatarUrl(backuserpath+us.getAvatarUrl());
        }
        return syUsers != null ? JsonData.buildSuccess(syUsers) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  管理后台管理员账号的账户是否启用
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/17 15:44
     **/
    @PostMapping("/updBackUserEnabled")
    public JsonData updBackUserEnabled(Integer userId,Integer enabled){
        int upd = personnelService.updBackUserEnabled(userId,enabled);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查看所有封禁用户
     * @return java.util.List<si.yun.entity.PerClosureUser> 
     * @Date 2021/8/21 8:47
     **/
    @RequestMapping("/selClosureUser")
    public List<PerClosureUser> selClosureUser(){
        List<PerClosureUser> perClosureUsers = personnelService.selClosureUser();
        return perClosureUsers;
    }
    /**
     * @Description  更改用户账号状态   封停用户账号
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/21 9:55
     **/
    @PostMapping("/updBackUserStatus")
    public JsonData updBackUserStatus(Integer userId,Integer enabled,Integer status){
        int upd = personnelService.updBackUserStatus(userId, enabled, status);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  更新后台管理员信息
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/25 10:11
     **/
    @PostMapping("/updBackUserInfo")
    public JsonData updBackUserInfo(PerBackUser user){
        int upd = personnelService.updBackUserInfo(user);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description
     * @return si.yun.utils.JsonData
     * @Date 2021/8/27 17:19
     **/
    @PostMapping("/updBackUserImg")
    public JsonData updBackUserImg(@RequestParam("file") MultipartFile files, HttpServletRequest request, int userId, HttpSession session) throws IllegalStateException, IOException {
        String realPath = importbackpath;
        String newName = uploadFile(files, request, session,realPath);
        int upd = personnelService.updBackUserImg(newName,userId);
        return upd != 0 ? JsonData.buildSuccess(upd) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  导入后台管理员
     * @return si.yun.utils.JsonData 
     * @Date 2021/8/27 20:05
     **/
    @PostMapping("/importExcelUser")
    public JsonData importExcelFile(@RequestParam("file") MultipartFile files, HttpServletResponse response, HttpSession session) throws Exception {
        List<PerBackUser> syUsers = new ArrayList<>();
        PerBackUser perBackUser = null;
        try{
            List<List<String>> lists = TemplateExcelUtil.readExcel(files.getInputStream());
            if(!CollectionUtils.isEmpty(lists)){
                for(int i=0;i<lists.size();i++){
                    List<String> list = lists.get(i);
                    perBackUser = createEqmPoi(list);
                    syUsers.add(perBackUser);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        int add =  personnelService.importExcelUser(syUsers);
        return add != 0 ? JsonData.buildSuccess(add) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    private PerBackUser createEqmPoi(List<String> list) {
        if(CollectionUtils.isEmpty(list)){
            return null;
        }else{
            PerBackUser perBackUser = new PerBackUser();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            //用户姓名  trueName
            String trueName = list.get(0);
            perBackUser.setTrueName(trueName);
            //用户性别  sex
            String sex = list.get(1);
            perBackUser.setSex(sex);
            //用户账号  account
            String account = list.get(2);
            perBackUser.setAccount(account);
            //用户头像  avatarUrl
            String avatarUrl = list.get(3);
            perBackUser.setAvatarUrl(avatarUrl);
            //用户邮箱   email
            String email = list.get(4);
            perBackUser.setEmail(email);
            //账户登录密码  password
            String password = list.get(5);
            if(password.contains(".0")){
                double pass = Double.parseDouble(password);
                int pwd =(int) pass;
                String pwdMd5 = String.valueOf(pwd);
                String md5 = Md5Utils.md5(pwdMd5);
                perBackUser.setPassword(md5);
            }else{
                String md5 = Md5Utils.md5(password);
                perBackUser.setPassword(md5);
            }
            //账户备注  remark
            String remark = list.get(6);
            perBackUser.setRemark(remark);
            //用户手机号  phoneNumber
            String phoneNumber = list.get(7);
            if(!phoneNumber.equals("")){
                perBackUser.setPhoneNumber(phoneNumber);
            }
            //身份证号码 idCard
            String idCard = list.get(8);
            perBackUser.setIdCard(idCard);
            //出生日期 birthDate
            String birthDate = list.get(9);
            if (!birthDate.equals("")){
                double bDate = Double.parseDouble(birthDate) ;
                Date bate = DateUtil.getJavaDate(bDate);
                String formatBirthDate = simpleDateFormat.format(bate);
                perBackUser.setBirthDate(formatBirthDate);
            }
            //所属部门 deptId
            String deptId = list.get(10);
            if (!deptId.equals("")) {
                double deptIds = Double.parseDouble(deptId);
                int dId = (int) deptIds;
                perBackUser.setDeptId(dId);
            }
            //账户个性签名 freestyle
            String freestyle = list.get(11);
            perBackUser.setFreestyle(freestyle);
            //获取本地ip
            try {
                String IP = InetAddress.getLocalHost().getHostAddress();
                perBackUser.setRegisterIp(IP);
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
            return perBackUser;
        }
    }
    /**
     * @Description  添加管理人员的图片
     * @return si.yun.utils.JsonData
     * @Date 2021/9/4 17:30
     **/
    @PostMapping("/addBackUserImg")
    public JsonData addBackUserImg(@RequestParam("file") MultipartFile files, HttpServletRequest request, HttpSession session) throws Exception {
        String realPath = importbackpath;
        String newName = uploadFile(files, request, session,realPath);
        session.setAttribute("backImgNewName",newName);
        int add = 1;
        return add != 0 ? JsonData.buildSuccess(add) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  添加后台管理人员
     * @return si.yun.utils.JsonData
     * @Date 2021/9/4 17:29
     **/
    @PostMapping("/addBackUserInfo")
    public JsonData addBackUserInfo(PerBackUser backUser,HttpSession session){
        String backImgNewName = (String)session.getAttribute("backImgNewName");
        backUser.setAvatarUrl(backImgNewName);
        String pwd = "123456";
        String password = Md5Utils.md5(pwd);
        backUser.setPassword(password);
        //获取本地ip
        try {
            String IP = InetAddress.getLocalHost().getHostAddress();
            backUser.setRegisterIp(IP);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        int add = personnelService.addBackUserInfo(backUser);
        return add != 0 ? JsonData.buildSuccess(add) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description   获取今年每月新增的用户数量（用户,后端）
     * @return si.yun.utils.JsonData 
     * @Date 2021/9/9 19:35
     **/
    @GetMapping("/selBeforeNum")
    public JsonData selBeforeNum(){
        List<Integer> userMonths = personnelService.selBeforeNum();
        return userMonths != null ? JsonData.buildSuccess(userMonths) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description   获取今年每月新增的用户数量（后端）
     * @return si.yun.utils.JsonData
     * @Date 2021/9/9 19:35
     **/
    @GetMapping("/selBackNum")
    public JsonData selBackNum(){
        List<Integer> userMonths = personnelService.selBackNum();
        return userMonths != null ? JsonData.buildSuccess(userMonths) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  获取人员登录总次数 成功次数（前端 ，管理端）
     * @return si.yun.utils.JsonData 
     * @Date 2021/9/10 9:48
     **/
    @GetMapping("/selLoginNums")
    public JsonData selLoginNums(){
        UserMonth  loginTime = personnelService.selLoginNums();
        return loginTime != null ? JsonData.buildSuccess(loginTime) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description   获取某一时间段内登录的数据(前)
     * @return si.yun.utils.JsonData
     * @Date 2021/9/9 19:35
     **/
    @GetMapping("/getLoginTime")
    public JsonData getLoginTime(){
        List<Integer>  loginTime = personnelService.getLoginTime();
        return loginTime != null ? JsonData.buildSuccess(loginTime) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description   获取某一时间段内登录的数据(管)
     * @return si.yun.utils.JsonData
     * @Date 2021/9/9 19:35
     **/
    @GetMapping("/getLoginTimes")
    public JsonData getLoginTimes(){
        List<Integer>  loginTime = personnelService.getLoginTimes();
        return loginTime != null ? JsonData.buildSuccess(loginTime) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询不同的反馈类型下不同的反馈结果数据
     * @return si.yun.utils.JsonData 
     * @Date 2021/9/10 14:17
     **/
    @PostMapping("/selFeedDatas")
    public JsonData selFeedDatas(Integer feedbackType){
        PerFeedData  perFeedData = personnelService.selFeedDatas(feedbackType);
        return perFeedData != null ? JsonData.buildSuccess(perFeedData) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询反馈的总数
     * @return si.yun.utils.JsonData 
     * @Date 2021/9/10 14:18
     **/
    @GetMapping("/selFeedBackNums")
    public JsonData selFeedBackNums(){
        PerFeedData  perFeedData = personnelService.selFeedBackNums();
        return perFeedData != null ? JsonData.buildSuccess(perFeedData) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查找反馈表图数据
     * @return si.yun.utils.JsonData
     * @Date 2021/9/10 14:25
     **/
    @PostMapping("/selFeedEcharts")
    public JsonData selFeedEcharts(Integer feedbackType){
        PerFeedData  perFeedData = personnelService.selFeedDatas(feedbackType);
        List<Integer> list = new ArrayList<>();
        list.add(perFeedData.getDataA());
        list.add(perFeedData.getDataB());
        list.add(perFeedData.getDataC());
        list.add(perFeedData.getDataD());
        return list != null ? JsonData.buildSuccess(list) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询不同类型下的课程视频播放量
     * @return si.yun.utils.JsonData
     * @Date 2021/9/10 19:10
     **/
    @GetMapping("/selCourseLookNum")
    public JsonData selCourseLookNum(){
        List<PerCourseLook>  perFeedData = personnelService.selCourseLookNum();
        return perFeedData != null ? JsonData.buildSuccess(perFeedData) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    /**
     * @Description  查询搜索统计量
     * @return si.yun.utils.JsonData 
     * @Date 2021/9/11 11:55
     **/
    @GetMapping("/selSearchNums")
    public JsonData selSearchNums(){
        List<SySearch>  sySearches = personnelService.selSearchNums();
        return sySearches != null ? JsonData.buildSuccess(sySearches) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }





    /**
     * @author: DZQ
     * @description: 审核列表内容
     * @date: 2021/8/9 9:12
     * @return  JsonData
     */
    //分页Table
    @PostMapping("/getTable")
    public JsonData getTable(String account, String nickname, String applyDate,Integer result) {
        List<Map<String,Object>> list=personnelService.getTable(account,nickname,applyDate,result);
        System.out.println(list);
        return list!=null? JsonData.buildSuccess(list) : JsonData.buildError("服务端异常");
    }
    /**
     * @author: DZQ
     * @description: 查询用户详情
     * @date: 2021/8/6 10:30
     * @return SyAudiTable对象
     */
    //查询
    @PostMapping("/view")
    public SyAudiTable view(Integer id , String result) {
        SyAudiTable tab = personnelService.view1(id,result);
        return tab;
    }
    /**
     * @author: DZQ
     * @description: 审核弹出层内容+
     * @date: 2021/8/6 10:29
     * @return SyAudiTable对象
     */
    //审核页面
    @PostMapping("/shenhe")
    public SyAudiTable shenhe(Integer id) {
        SyAudiTable tab1 = personnelService.view(id);
        return tab1;
    }

    /**
     * @author: DZQ
     * @description: 高级检索获得内容
     * @date: 2021/8/6 10:29
     * @return JsonData
     */
    @PostMapping("/SelNumber")
    public JsonData getTable_1(String account,String phone,String position,String nickname){
        List<Map<String,Object>> list=personnelService.getTable1(account,phone,position,nickname);
        return list!=null? JsonData.buildSuccess(list) : JsonData.buildError("服务端异常");
    }

    /**
     * @author: DZQ
     * @description: 审核详情页面通过按钮
     * @date: 2021/8/13 9:59
     * @return
     */
    @PostMapping("/audit")
    public JsonData audit(String textarea,String remarks,String applyDate,String position,Integer launchId,Integer pass){
        int sel=personnelService.audit(textarea,remarks,applyDate,position,launchId,pass);
        return  sel!=0? JsonData.buildSuccess(sel):JsonData.buildError("服务端异常");
    }

    /**
     * @author: DZQ
     * @description: 驳回按钮
     * @date: 2021/8/30 18:58
     * @return
     */
    @PostMapping("/rejected")
    public JsonData rejected(String textarea,String remarks,String applyDate,String position,Integer launchId,Integer pass){
        int sel=personnelService.rejected(textarea,remarks,applyDate,position,launchId,pass);
        return  sel!=0? JsonData.buildSuccess(sel):JsonData.buildError("服务端异常");
    }


    /**
     * @author: DZQ
     * @description: 查看已审核，已通过，已驳回表格
     * @date: 2021/8/13 9:52
     * @return
     */
    @PostMapping("/SelTab")
    public JsonData SelTab(String result){
        List<Map<String,Object>> list=personnelService.SelTab(result);
        return list!=null? JsonData.buildSuccess(list) : JsonData.buildError("服务端异常");
    }
    /**
     * @author: DZQ
     * @description: 获取未审核，通过，驳回数量
     * @date: 2021/8/15 9:53
     * @return
     */
    @PostMapping("/getNumber")
    public Map<String,Object> getNumber(int result1,int result2,int result3){
        Map<String,Object> list=personnelService.getNumber(result1,result2,result3);
        return list;
    }
    /**
     * @author: DZQ
     * @description: 审核通过信息
     * @date: 2021/9/4 14:39
     * @return
     */
    @PostMapping("/Review")
    public SyAudiTable Review(Integer id) {
        SyAudiTable tab = personnelService.Review(id);
        return tab;
    }
    /**
     * @author: DZQ
     * @description: 审核驳回信息
     * @date: 2021/9/4 14:39
     * @return
     */
    @PostMapping("/check")
    public SyAudiTable check(Integer id) {
        SyAudiTable tab = personnelService.Review(id);
        return tab;
    }

    /**
     * @descript: 后台审核日志
     * @return
     * @dare :2021/8/15 17:58
     */
    @PostMapping("/GetTab")
    public JsonData GetTab(int loginType){
        List<Map<String,Object>> list=personnelService.GetTab(loginType);
        return list!=null? JsonData.buildSuccess(list) : JsonData.buildError("服务端异常");
    }
    /**
     * @descript: 前台审核日志
     * @return
     * @dare :2021/8/15 17:58
     */
    @PostMapping("/ConLog")
    public JsonData ConLog(int loginType){
        List<Map<String,Object>> list=personnelService.ConLog(loginType);
        return list!=null? JsonData.buildSuccess(list) : JsonData.buildError("服务端异常");
    }
    /**
     * @author: DZQ
     * @description: 查询前台用户按钮
     * @date: 2021/9/11 18:50
     * @return list
     */
    @PostMapping("/deskUser")
    public JsonData deskUser(String loginLocation,String realName,Integer loginState,Integer loginType){
        List<Map<String,Object>> list=personnelService.deskUser(loginLocation,realName,loginState,loginType);
        return list!=null?JsonData.buildSuccess(list) : JsonData.buildError("服务端异常");
    }
    /**
     * @author: DZQ
     * @description: 查询后台用户按钮
     * @date: 2021/9/11 18:51
     * @return list
     */
    @PostMapping("/Background")
    public JsonData Background(String loginLocation,String trueName,Integer loginState,Integer loginType){
        List<Map<String,Object>> list=personnelService.Background(loginLocation,trueName,loginState,loginType);
        return list!=null?JsonData.buildSuccess(list) : JsonData.buildError("服务端异常");
    }

    /**
     * @author: DZQ
     * @description:  获取前后台登录日志总数
     * @date: 2021/9/11 20:42
     * @return map
     */
    @PostMapping("/getTotal")
    public JsonData getTotal(Integer result1,Integer result2){
        Map<String,Object> map=personnelService.getTotal(result1,result2);
        return map!=null?JsonData.buildSuccess(map) : JsonData.buildError("服务端异常");
    }
}
